package com.itheima.ticket.ticket03;

public class Ticket implements Runnable {
    private static int ticket = 100;

    @Override
    public void run() {
        while (true) {
            if (ticket > 0) {
                maipiao();
            } else {
                break;
            }


        }
    }
    //static  Ticket.class
    private  synchronized void maipiao() {
        ////自带一个this
        //人有操作  耗时间
        if(ticket>0){
            try {
                Thread.sleep(10);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            System.out.println(Thread.currentThread().getName() + "正在卖" + ticket + "张票");
            ticket--;
        }
    }
}
